package com.bs.visitservice.controller.user;

import com.bs.visitservice.cache.impl.JedisLoginCache;
import com.bs.visitservice.service.DiscountCouponService;
import com.bs.visitservice.utils.Result;
import com.bs.visitservice.utils.ResultUtil;
import com.bs.visitservice.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询用户可用券
 */
@RestController
public class DiscountCouponController {
    @Autowired
    private DiscountCouponService discountCouponService;

    @Autowired
    private JedisLoginCache jedisCacheManager;

    /**
     * 查询用户可用的平台优惠券
     * @return
     */
    @RequestMapping(value = "/user/queryPlatform",method = RequestMethod.POST)
    public Result queryPlatform(){
        Map<String,Object> cond = new HashMap();
        Long userNo = (Long) ThreadLocalUtil.get("loginNo");;
        cond.put("userNo", userNo);
        List<Map<String, Object>> datas = discountCouponService.queryDiscountByUser(cond);
        ResultUtil.transfort(datas, getDictMap(), true);
        return Result.success(datas);
    }

    /**
     * 查询用户可用的商家优惠券
     * @param cond
     * @return
     */
    @RequestMapping(value = "/userpublic/querySellerDiscount",method = RequestMethod.POST)
    public Result querySellerDiscount(@RequestBody  Map cond){
        List<Map<String, Object>> datas = discountCouponService.queryDiscountSeller(cond);
        ResultUtil.transfort(datas, getDictMap(), true);
        return Result.success(datas);
    }

    /**
     * 获取列和字典值的映射关系
     * @return
     */
    private Map getDictMap(){
        Map<String,String> dictMap = new HashMap<>();
        return dictMap;
    }
}
